
if($('.middle').html==''){
    $('.empty').display='block';
}else{
    $('.empty').display='none';
}
$(function () {
    $.ajax({
        url:'/car/things',
        type:'post',
        success:function (data) {
            showThings(data);
        },
        error:function (err) {
            console.log('error'+err);
        }
    })

})
function showThings(data) {
    for(var i=0;i<data.length;i++){
        var imgsrc=data[i].image;
        var number=data[i].number;
        var addDiv=$('<div class="car-div">\n' +
            '                <input type="checkbox" class="checkbox">\n' +
            '                <div class="detail-div">\n' +
            '                <img src="'+data[i].image+'" alt="">\n' +
            '                <p class="title">title:'+data[i].title+'</p>\n' +
            '                <p class="kind">kind:'+data[i].kind+'</p>\n' +
            '                <p class="price">price:'+data[i].price+'</p>\n' +
            '                </div>\n' +
            '                <p><span class="minus">-</span><span class="number">'+data[i].number+'</span><span class="add">+</span>\n' +
            '                </p>\n' +
            '                <span class="total">total:'+data[i].price*data[i].number+'</span>\n' +
            '                <input type="button" class="delete" value="delete">\n' +
            '                <input type="button" class="submit" value="submit">\n' +
            '          </div>');
        $('.middle').append(addDiv);
        $('.delete').click(function () {
            $.ajax({
                url:'/car/delete',
                type:'post',
                data:{imgsrc:imgsrc},
                success:function (data){
                    location.reload();
                },
                error:function (e) {
                    console.log('error'+e);
                }
            })
        })
        $('.add').click(function () {
            $.ajax({
                url:'/car/modify',
                type:'post',
                data:{number:number,imgsrc:imgsrc},
                success:function (data) {
                    location.reload();
                },
                error:function (e) {
                    console.log('error'+e);
                }
            })
        })
    }
}


